<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://chances.com.cn/jsp/epgutils" prefix="epgutils"%>
<epgutils:wechatUrl var="bindListUrl" action="bindList" from="null" path="/wechat/bind/list.wx"/>
<epgutils:wechatUrl var="playUrl" action="play" from="null" path="/wechat/play/program.wx"/>
<epgutils:wechatUrl var="playCtrlUrl" action="playctrl" from="null" path="/wechat/play/playctrl.wx"/>
<epgutils:wechatUrl var="playStatusUrl" action="playStatus" path="/wechat/play/status.wx"/>
<script>
	var stbPlayUrl = "${playUrl}";
	var playCtrlUrl = "${playCtrlUrl}";
</script>
<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/swiper.min.css" />
<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/mobile.css" />
<link rel="stylesheet" type="text/css" href="${_contextPath}/sites/weixin/css/weui.min.css" />
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/jquery.min.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/jquery.lazyload.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/bootstrap-dialog.min.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/touch_scroller.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/swiper.min.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/weixin-ajax.js"></script>
<script type="text/javascript" src="${_contextPath}/sites/weixin/js/vue.js"></script>

<script>
var personUrl = "${personUrl}";
var isGuest = ${EPG_USER_SESSION.isGuest};

function getBinds(){
	if("${EPG_USER_SESSION.userId}" == ""){
		return;
	}
	$.ajax({
		method:"get",
		url:"${bindListUrl}?userId=${EPG_USER_SESSION.userId}",
		async:false,
		success:function(data){
			console.log(data);
			weixinOption.bind = data.result;
			//alert(data);
		},
		failure:function(){
			console.log("failed");
		}
	});
}
function isOnline(stbNo,online,offline){
	online();
	/* $.ajax({
		method:"get",
		url:"${playStatusUrl}?stbNo="+stbNo,
		aysnc:false,
		success:function(data){
			if(data.result){
				if( "0"  == data.result.res_code ||  0  == data.result.res_code){
					online(data);
				}else{
					//offline(data);
				}
			}
		},
		failure:function(){
			console.log("failed");
		}
	}); */
}

function addToHistory(params){
	var fields = {}; 
	fields.contentId = params.code;
	fields.contentName = params.title;
	fields.contentPoster = params.icon;
	fields.contentType = params.type;
	fields.path = params.prog;
	fields.userId = params.userId;
	$.ajax({
		method:"get",
		url:"${_contextPath}/user/history/add",
		data:fields,
		aysnc:true,
		success:function(data){},
		error:function(){}
	});
}
var weixinOption = {
		isguest:${EPG_USER_SESSION.isGuest},
		contextPath:"${_contextPath}",
		nickName:"${EPG_USER_SESSION.nickname}",
		headImage:"",
		loginUrl:"",
		bind:[],
		curStbNo:"${EPG_USER_SESSION.stbNo}",
		getStbNo:function(){
			var stbs = this.bind; 
			var len = stbs.length;
			//var stbNo = this.curStbNo;
			var stbNo = "";
			if(len > 0){
				stbNo = stbs[len - 1].stbNo;
			}
			return stbNo;
		},
		isBind:function(){
			return this.getStbNo() != "";
		}
};
//$(document).ready(function(){getBinds();});
getBinds();
if("${EPG_USER_SESSION.isGuest}" == "" || ${EPG_USER_SESSION.isGuest}){
	
}
var epgConfig = new EpgConfig(weixinOption);
var bindCtrl = new BindCtrl(epgConfig);
var favCtrl = new FavCtrl(epgConfig);
var photoCtrl = new PhotoCtrl(epgConfig);
var subCtrl = new SubscriberCtrl(epgConfig);
var stbCtrl = new StbCtrl(epgConfig);

var remoteCtrl_min = "<%=request.getContextPath()%>/remote/rc_min.jsp";
var remoteCtrl_full = "<%=request.getContextPath()%>/remote/rc_full.jsp";
var remoteCtrlDialog = new RemoteCtrlDialog(remoteCtrl_min, remoteCtrl_full);

function gotoLink(url, focusId) {
	var gotoUrl = url;
	if (arguments.length > 1) {
		var fix = (url.indexOf("?") != -1) ? "&" : "?";
		gotoUrl = url + fix + "lfid=" + focusId;
	}
	window.location.href = gotoUrl;
}
function confirmBind(url,focusId){
	stbs = weixinOption.bind; 
	if(stbs.length >= 1){
		 gotoLink(url, focusId)
	}else{
		gotoLink("${personUrl}",focusId);
	}
}
function collect(contentId,contentName,contentPoster,contentType,path,userId,category){
	stbs = weixinOption.bind; 
	if(stbs.length >= 1){
		var content = new EpgCollection(contentId,contentName,contentPoster,contentType,path,userId,category);
		showLoading('收藏处理中');
		if(favStorage.exist(content.contentId)){
			favCtrl.remove(userId,content.contentId,function (){
				favStorage.remove(content.contentId);
				var src = "${_contextPath}/sites/weixin/images/wx_collect.png";
				setTimeout("hideAlert('取消收藏成功','collectImage','"+ src +"')",2000);
			});
		}else{
			favCtrl.add(content,function (){
				favStorage.add(content);
				var src = "${_contextPath}/sites/weixin/images/wx_collected.png";
				setTimeout("hideAlert('收藏成功','collectImage','"+ src +"')",2000);
			});
		}
	}else{
		gotoLink("${personUrl}","detailPage");
	}
}
function initCollectImage(contentCode){
	if(favStorage.exist(contentCode)){
		//$("#collectImage").removeClass("glyphicon-star-empty").addClass("glyphicon-star");
		$("#collectImage").attr("src","${_contextPath}/sites/weixin/images/wx_collected.png");
	}
}
function priorityImage(icon,poster,defImg){
	if(strExist(icon)){
		if(icon.indexOf("http") == -1){
			return "${_resourcePath}"+icon;
		}else{
			return icon;
		}
	}else if(strExist(poster)){
		if(poster.indexOf("http") == -1){
			return "${_resourcePath}"+poster;
		}else{
			return poster;
		}
	}else{
		return "${_templatePath}/images/"+defImg;
	}
}
</script>